Imports MyClasses
Imports System.Data
Imports System.Data.SqlClient
Public Class DDocument
    Public Shared Function SaveData(ByVal Cdoc As CDocument, ByVal SaveUpdate As String) As Boolean
        Dim strSql As String = ""
        Dim dbConnection As New dbAccess
        Dim param(6) As SqlParameter
        Try
            dbConnection.BeginTransaction()

            If SaveUpdate = "U" Then
                strSql = " UPDATE mLayoutSet SET Height = @height, Width = @width, TopM =@topM, BottomM =@bottomM, " & _
                         " LeftM = @leftM, RightM = @rightM , Layoutlbl = @layoutlbl WHERE LayoutId =" & Cdoc.LayoutId

                param(0) = New SqlParameter("@height", IIf(Cdoc.Height = Nothing, 0, Cdoc.Height))
                param(1) = New SqlParameter("@width", IIf(IsNothing(Cdoc.Width), 0, Cdoc.Width))
                param(2) = New SqlParameter("@topM", IIf(IsNothing(Cdoc.TopMargin), 0, Cdoc.TopMargin))
                param(3) = New SqlParameter("@bottomM", IIf(IsNothing(Cdoc.BottomMargin), 0, Cdoc.BottomMargin))
                param(4) = New SqlParameter("@leftM", IIf(IsNothing(Cdoc.LeftMargin), 0, Cdoc.LeftMargin))
                param(5) = New SqlParameter("@rightM", IIf(IsNothing(Cdoc.RightMargin), 0, Cdoc.RightMargin))
                param(6) = New SqlParameter("@layoutlbl", Cdoc.LayoutLabel)

                dbConnection.ExecuteNonQuery(strSql, param)
            Else
                ReDim param(8)

                strSql = " INSERT INTO mLayoutSet(LayoutId, Height, Width, TopM, BottomM, LeftM, RightM, Type, Layoutlbl)" & _
                         " VALUES(@uid, @height, @width, @topM, @bottomM, @leftM, @rightM, @type, @layoutlbl)"
                Cdoc.LayoutId = DGeneral.GetSeqNum("LAYOUT")
                param(0) = New SqlParameter("@uid", Cdoc.LayoutId)
                param(1) = New SqlParameter("@height", IIf(Cdoc.Height = Nothing, 0, Cdoc.Height))
                param(2) = New SqlParameter("@width", IIf(IsNothing(Cdoc.Width), 0, Cdoc.Width))
                param(3) = New SqlParameter("@topM", IIf(IsNothing(Cdoc.TopMargin), 0, Cdoc.TopMargin))
                param(4) = New SqlParameter("@bottomM", IIf(IsNothing(Cdoc.BottomMargin), 0, Cdoc.BottomMargin))
                param(5) = New SqlParameter("@leftM", IIf(IsNothing(Cdoc.LeftMargin), 0, Cdoc.LeftMargin))
                param(6) = New SqlParameter("@rightM", IIf(IsNothing(Cdoc.RightMargin), 0, Cdoc.RightMargin))
                param(7) = New SqlParameter("@type", "SALE")
                param(8) = New SqlParameter("@layoutlbl", Cdoc.LayoutLabel)

                dbConnection.ExecuteNonQuery(strSql, param)
            End If

            dbConnection.CommitTransaction()
            Return True

        Catch ex As Exception
            dbConnection.RollBackTransaction()
            DGeneral.ErrorHandler(ex.Message, "DAL", "DDocument", "SaveData", strSql)
            Return False
        End Try
    End Function
    Public Shared Function GetData(ByVal intLayoutId As Integer) As DataTable
        Dim strSql As String = ""
        Try
            strSql = "select LayoutId, Height, Width, TopM, BottomM, LeftM, RightM, Type, Layoutlbl " & _
                     " from mLayoutset where LayoutId =" & intLayoutId
            Return DbHelper.ExecuteDataTable(strSql)
        Catch ex As Exception
            Return Nothing
            DGeneral.ErrorHandler(ex.Message, "DAL", "DDocument", "GetData", strSql)
        End Try
    End Function
End Class
